﻿// Copyright (c) 2012 - 2020 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2018-12-05 version 3.1.5 Jared Zheng <jaredz at outlook dot com>

#ifndef __COMMON_DLG_H__
#define __COMMON_DLG_H__

#pragma once

#include "xui.h"
#include "xuikit.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 服务器界面TAB子对话框基类
class ICommonServer;
class CCommonDlg : public CXDlg, public CEventHandler
{
public:
    enum DLG_ITEM
    {
        DLG_ITEM_GRAP   = 2,
        DLG_ITEM_HEIGHT = 18,
        DLG_ITEM_WIDTH  = 300,
    };
public:
    CCommonDlg(void);
    virtual ~CCommonDlg(void);

    Int   GetTabIndex(void);
    void  SetTabIndex(Int nIndex);

    ICommonServer* GetServer(void);
    void           SetServer(ICommonServer* pServer);
    // CEventHandler
    virtual UInt OnHandle(Int nEvent, uintptr_t utData, ULLong ullParam) OVERRIDE;
    virtual UInt OnHandle(Int nEvent, CEventBase& pParam, ULLong ullParam) OVERRIDE;
    virtual UInt OnHandle(Int nEvent, CStream& Stream, ULLong ullParam) OVERRIDE;
    virtual UInt OnHandle(Int nEvent, UInt uCount) OVERRIDE;
protected:
    virtual void OnLive(bool bStart) PURE;
    virtual void OnLink(Int nServerIndex, uintptr_t utData) PURE;
    virtual void OnUpdate(Int nServerIndex, uintptr_t utData) PURE;
    virtual void OnSync(Int nServerIndex, uintptr_t utData) PURE;
    virtual void OnSync(Int nServerIndex, CStream& Stream) PURE;
    virtual void OnUnlink(Int nServerIndex, uintptr_t utData) PURE;

    virtual void UpdateServerInfo(void) PURE;

    virtual CXListView* GetListView(Int nServerIndex) PURE;

    void  InitServerData(Int nServerIndex);
    Int   InitServerCommonData(Int nServerIndex); // 
    bool  AddServerData(Int nServerIndex, uintptr_t utData);
    bool  UpdateServerData(Int nServerIndex, uintptr_t utData);
    bool  RemoveServerData(Int nServerIndex, uintptr_t utData);

    void  AddServerDataAddr(Int nServerIndex, Int nIndex, void* pAddr);
protected:
    Int              m_nTabIndex;
    ICommonServer*   m_pServer; // 
};

INLINE CCommonDlg::CCommonDlg(void)
: m_nTabIndex(-1)
, m_pServer(nullptr)
{
    AddRef(); // 
}

INLINE CCommonDlg::~CCommonDlg(void)
{
}

INLINE Int CCommonDlg::GetTabIndex(void)
{
    return m_nTabIndex;
}

INLINE void CCommonDlg::SetTabIndex(Int nIndex)
{
    m_nTabIndex = nIndex;
}

INLINE ICommonServer* CCommonDlg::GetServer(void)
{
    return m_pServer;
}

INLINE void CCommonDlg::SetServer(ICommonServer* pServer)
{
    m_pServer = pServer;
}

#endif // __COMMON_DLG_H__
